package com.symaster.common.swing.entity;

import org.apache.commons.lang3.StringUtils;

import javax.swing.*;
import java.awt.*;

public class ConfigSettingDialogItem extends JPanel {

    private final String key;
    private final String likeName;
    private final String defaultValue;
    private JTextField textField;

    public ConfigSettingDialogItem(String key, String likeName, String defaultValue) {
        this.key = key;
        this.likeName = likeName;
        this.defaultValue = defaultValue;
        initPage();
    }

    private void initPage() {
        setLayout(new BorderLayout());
        JLabel label = new JLabel(StringUtils.isEmpty(likeName) ? key : likeName);
        textField = new JTextField(defaultValue);
        add(label, BorderLayout.WEST);
        add(textField, BorderLayout.CENTER);
    }

    public String getValue() {
        if (textField != null) {
            return textField.getText();
        }
        return null;
    }

    public String getKey() {
        return key;
    }

    public String getLikeName() {
        return likeName;
    }
}